// socket_client.h
#ifndef SOCKET_CLIENT_H
#define SOCKET_CLIENT_H

#ifdef _WIN32
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #pragma comment(lib, "ws2_32.lib")
    typedef SOCKET socket_t;
#define close_socket(s) closesocket(s)
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
typedef int socket_t;
#define close_socket(s) close(s)
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif

#include <stddef.h>
#include <stdint.h>
// 结构定义
typedef enum {
    TCP_MODE,
    UDP_MODE
} socket_mode_t;

typedef enum {
    STATE_DISCONNECTED,
    STATE_CONNECTING,
    STATE_CONNECTED,
    STATE_RECONNECTING
} connection_state_t;

typedef struct {
    char* server_ip;
    int server_port;
    socket_mode_t mode;
    int heartbeat_interval; // 心跳间隔(秒)
    int reconnect_interval; // 重连间隔(秒)
} connection_config_t;

typedef struct {
    void (*on_connected)(void);
    void (*on_disconnected)(void);
    void (*on_message_received)(const char* data, size_t length);
    void (*on_error)(const char* error_msg);
} event_callbacks_t;

typedef struct socket_client_s socket_client_t;
// 上述结构定义和枚举...

// API函数
socket_client_t* socket_client_create(const connection_config_t* config, const event_callbacks_t* callbacks);
int socket_client_connect(socket_client_t* client);
int socket_client_disconnect(socket_client_t* client);
int socket_client_send(socket_client_t* client, const char* data, size_t length);
int socket_client_destroy(socket_client_t* client);
void socket_client_set_log_enabled(socket_client_t* client, int enabled);

#endif // SOCKET_CLIENT_H